//
//  CountDownVC.m
//  SYPerfectDemo
//
//  Created by Lssyyy on 2019/1/10.
//  Copyright © 2019年 Lssyyy. All rights reserved.
//

#import "CountDownVC.h"
#import "CountDownManager.h"
@interface CountDownVC ()
@property (weak, nonatomic) IBOutlet UILabel *timeLb;

@end

@implementation CountDownVC
static NSString * const kCountdownKey = @"ttttt";
static NSTimeInterval const kCountdownTimeInterval = 60;
- (void)viewDidLoad {
    [super viewDidLoad];
    CountdownTask *task = nil;
    if ([[CountdownManager defaultManager]countdownTaskExistWithKey:kCountdownKey task:&task]) {
        [self beginCounting];
    }
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
}
- (IBAction)btnMethod:(UIButton *)sender {
    switch (sender.tag) {
        case 0:{
            [self beginCounting];
        }
            break;
            //暂停
        case 1:
            
            break;
            //继续
        case 2:
            
            break;
        case 3:
            
            break;
            //重置
        default:
            break;
    }
}

- (void)dealloc{
    NSLog(@"销毁了");
    [[CountdownManager defaultManager]closeCountDownWithKey:kCountdownKey];
    
}


- (void)beginCounting {
    [[CountdownManager defaultManager]schedulCountDownWithKey:kCountdownKey timeInterval:kCountdownTimeInterval countingDown:^(NSTimeInterval leftTimeInterval) {
        self.timeLb.text = [NSString stringWithFormat:@"%.0fs",leftTimeInterval];
    } finished:^(NSTimeInterval finalTimeInterval) {
        NSLog(@"最后的时间%@",[NSString stringWithFormat:@"%.0fs",finalTimeInterval]);
    }];
}
@end
